<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>批发表</title>
<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
<style>
body {
	margin: 10px;
}

.demo-carousel {
	height: 300px;
	line-height: 300px;
	text-align: center;
}

.demoTable {
	z-index: 10px;
}

#addReload {
	position: absolute;
	top: 0%;
	z-index: 100px;
	background: rgb(0, 0, 0, 0.9);
	width: 100%;
	height: 100%;
	display: none;
}

#addOperation {
	position: absolute;
	left: 30%;
	top: 0%;
	width: 40%;
	background: white;
}

#updateReload {
	position: absolute;
	top: 0%;
	z-index: 100px;
	background: rgb(0, 0, 0, 0.9);
	width: 100%;
	height: 100%;
	display: none;
}

#updateOperation {
	position: absolute;
	left: 30%;
	top: 0%;
	width: 40%;
	background: white;
}
</style>
</head>
<body>
	<div class="demoTable">
		搜索关键字：
		<div class="layui-inline" >
			<input class="layui-input" name="id" id="demoReload"
				autocomplete="off">
		</div>
		
		时间：
		<div class="layui-input-inline">
      	  	<input name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
      	——<div class="layui-input-inline">
      	  	<input name="date" id="date1" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
      	订单状态：
      	
      	<div class="layui-inline layui-form" style="width:130px">
			<select name="shzt" id="shzt"
				autocomplete="off" class="layui-input">
				<option></option>
				<option value="0">审核不通过</option>
				<option value="1">等待审核</option>
				<option value="2">审核通过</option>
			</select>
	  	</div>
		<button class="layui-btn" data-type="reload">搜索</button>
		<button class="layui-btn" id="memberAdd" data-type="add">增加</button>
		<table class="layui-hide" id="menber" lay-filter="demo"></table>
	</div>

	<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="detail" >查看详情</a>
{{# if(d.isva==1){ }}
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	{{# } else if(d.isva==2){}}
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="salesReturn">退货</a>
	{{# }else if(d.isva==0){}}
		<a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="xgsh">修改</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	{{# } }}
  
</script>

	<script src="../../res/js/jquery-1.10.2.js"></script>
	<script src="../../res/js/layui-xtree.js"></script>
	<script src="../../layui/layui.js"></script>
	<script src="../../res/js/base.js"></script>
	<script>

layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function(){
  var form = layui.form
  ,laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
  var path=getRootPath();
  //日期
  laydate.render({
	    elem: '#date'
  });
  laydate.render({
	    elem: '#date1'
  });
  
  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });
  
  //执行一个 table 实例
  table.render({
     elem: '#menber'
    ,async: false
    ,height: 474
    ,url: path+'wholesale/wholesaleFindAll.action' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {field: 'pfSerialNumber', title: '流水号', width:120}
      ,{field: 'pfNumber', title: '数量', width:120,sort: true}
      ,{field: 'pfTotalMoney', title: '总金额', width:120,sort: true}
      ,{field: 'pfPerson', title: '操作人', width:120,sort: true}
      ,{field: 'pfDates', title: '批发时间', width:150,sort: true}
      ,{field: 'state', title: '状态', width:120,sort: true}
      ,{fixed: 'right',title: '操作', width: 265, align:'center', toolbar: '#barDemo'}
    ]]
  	,id: 'testReload'
  });
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    var pfId = data.pfId;
    if(layEvent === 'del'){
      var id=data.pfId;
      layer.confirm('确认删除？', function(index){
        obj.del(); //删除对应行（tr）的DOM结构
        layer.close(index);
        //使用jquery的ajax方式向后台提交数据
		var url = path+"wholesale/deleteWholesale.action";
		var data={pfId:id};
			$.post(url,data,function(data){
				
				if(data=="ok"){
					layer.msg('删除成功', {
						  icon: 1,
						  time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
						  
					});
				}
			});
      	});
    } else if(layEvent === 'edit'){
	      
	      
		}else if(layEvent === 'salesReturn'){
	    	/* var url = path+"salesReturn/findAllFdSellDetail.action";
	    	var data={reId:reId};
			$.post(url,data,function(data){
				alert("234");
			}); */
			
			//sessionStorage['sellId'] = sellId;
			layer.open({
				title:'退货详情'
				,type:2
				,area:['85%','80%']
				,content:[path+'pages/yq/wholesaleDetail.html?pfId='+pfId,'no']
			});
	 
	    }else if(layEvent === 'detail'){
	    	
	    	layer.open({
				title:'批发订单详情'
				,type:2
				,area:['50%','70%']
				,content:[path+'pages/yq/wholesaleDetails.html?pfId='+pfId,'no']
			});
	    }else if(layEvent == "xgsh"){
	    	var sum=data.pfNumber;
	    	var total=data.pfTotalMoney;
	    	layer.open({
				  type: 2,
				  area : ['75%' , '80%'],//弹出框大小
				  shift:1,//弹出框动画效果
				  content: [path+'pages/yq/wholesaleUpdate.html?pfId='+pfId+'&sum='+sum+'&total='+total,'on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			 	  success:function(layero,index){
			 		  var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
			 		  var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
			 	  }
			});
	    	
	    }
	});

		//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			var demoReload = $('#demoReload');
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					pfPerson : demoReload.val(),
					dateOne: $("#date").val(),
					dateTwo: $("#date1").val(),
					isva : $("#shzt").val()
				}
			});
		});
			
		$('#memberAdd').on('click', function() {
			layer.open({
				  type: 2,
				  area : ['75%' , '80%'],//弹出框大小
				  shift:1,//弹出框动画效果
				  content: ['wholesaleAdd.html','on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			 	  success:function(layero,index){
			 		  var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
			 		  var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
			 	  }
			});
			
		});

	});
</script>
</body>
</html>